/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
// 集中在状态机中管理分类数据
import { defineStore } from "pinia";
import { ClassifyType } from "../types/pro";
import { classifyGet } from "../api/pro";
interface ClassifyStateType {
  list: Array<ClassifyType>;
}
export const useClassify = defineStore("classify", {
  state: (): ClassifyStateType => ({
    list: [{ name: "分类名称", icon: "" }],
  }),
  getters: {
    parentList(): ClassifyType[] {
      let arr = this.list.filter((item) => item.parent == "0-0");
      return arr;
    },
  },
  actions: {
    //异步action
    async initClassifyList() {
      let res = await classifyGet(true);
      this.list = res.data.results;
    },
  },
});
